import pandas as pd

from openpyxl import load_workbook
from openpyxl.formatting.rule import CellIsRule
from openpyxl.styles import Font, Alignment, PatternFill, Border, Side

import util.lib as lib
import util.mydecorator as mydecorator

import format


@mydecorator.calTime
def job():
    # 加载 Excel 文件
    wb = load_workbook(lib.data_path + 'de_sum.xlsx')

    de_sum_rule = CellIsRule(operator='lessThan', formula=[-10], stopIfTrue=True, fill=format.green_fill)

    # 获取当前 Sheet
    sheet = wb['Sheet1']

    # 冻结首行（第一行）
    sheet.freeze_panes = 'A2'  # 表示冻结 A2 单元格上方的行（即第一行）

    # 设置第一列的宽
    sheet.column_dimensions['A'].width = 30 

    sheet.conditional_formatting.add('D2:D55550', de_sum_rule)
    sheet.conditional_formatting.add('F2:F55550', format.week_pct_rule)
    sheet.conditional_formatting.add('G2:G55550', format.week_pct_rule)

    wb.save(lib.data_path + 'de_sum_v.xlsx')


if __name__ == '__main__':
    job()